package com.tiantai.tea.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiantai.common.annotation.Log;
import com.tiantai.common.core.controller.BaseController;
import com.tiantai.common.core.domain.AjaxResult;
import com.tiantai.common.enums.BusinessType;
import com.tiantai.tea.domain.TeaActivity;
import com.tiantai.tea.service.ITeaActivityService;
import com.tiantai.common.utils.poi.ExcelUtil;
import com.tiantai.common.core.page.TableDataInfo;

/**
 * 活动管理Controller
 *
 * @author handsomedog
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/tea/activity")
public class TeaActivityController extends BaseController
{
    @Autowired
    private ITeaActivityService teaActivityService;

    /**
     * 查询活动管理列表
     */
    //@PreAuthorize("@ss.hasPermi('tea:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaActivity teaActivity)
    {
        startPage();
        List<TeaActivity> list = teaActivityService.selectTeaActivityList(teaActivity);
        return getDataTable(list);
    }

    /**
     * 导出活动管理列表
     */
    @PreAuthorize("@ss.hasPermi('tea:activity:export')")
    @Log(title = "活动管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaActivity teaActivity)
    {
        List<TeaActivity> list = teaActivityService.selectTeaActivityList(teaActivity);
        ExcelUtil<TeaActivity> util = new ExcelUtil<TeaActivity>(TeaActivity.class);
        util.exportExcel(response, list, "活动管理数据");
    }

    /**
     * 获取活动管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('tea:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaActivityService.selectTeaActivityById(id));
    }

    /**
     * 新增活动管理
     */
    @PreAuthorize("@ss.hasPermi('tea:activity:add')")
    @Log(title = "活动管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaActivity teaActivity)
    {
        return toAjax(teaActivityService.insertTeaActivity(teaActivity));
    }

    /**
     * 修改活动管理
     */
    @PreAuthorize("@ss.hasPermi('tea:activity:edit')")
    @Log(title = "活动管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaActivity teaActivity)
    {
        return toAjax(teaActivityService.updateTeaActivity(teaActivity));
    }

    /**
     * 删除活动管理
     */
    @PreAuthorize("@ss.hasPermi('tea:activity:remove')")
    @Log(title = "活动管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaActivityService.deleteTeaActivityByIds(ids));
    }
}
